package com.kexin.common.utils;

import java.lang.reflect.Method;
import java.util.List;

public class Node<T> {
    private Integer id;
	protected T node;
	protected List<Node> children;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Node(T node){
		this.node=node;
		this.id=this.getNodeId();

	}

    public T getNode() {
        return node;
    }

    public void setNode(T node) {
        this.node = node;
        this.id=this.getNodeId();
    }

    public List<Node> getChildren() {
        return children;
    }

    public void setChildren(List<Node> children) {
        this.children = children;
    }


    private Integer getNodeId(){
	    if (this.node!=null){
	        Method m;
            try {
                m = this.node.getClass().getDeclaredMethod("getId");
                return (Integer) m.invoke(node);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
